package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页Vo
 */
public class OrderConfirmVo {
    @Getter
    @Setter
    List<MemberAddressVo> address; //订单地址展示列表
    @Getter
    @Setter
    List<OrderItemVo> items;//所有选中的购物项

    @Getter
    @Setter
    String orderToken;//防重令牌

    //发票。。。
    @Getter
    @Setter
    Integer integration;//优惠券信息

    @Getter
    @Setter
    Map<Long,Boolean> hasStock;//是否有库存

//    BigDecimal total; //订单总额

    public BigDecimal getTotal() {  //计算订单总额
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum  = sum.add(multiply);
            }
        }
        return sum;
    }

//    BigDecimal payPrice;//应付价格
    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum  = sum.add(multiply);
            }
        }
        return sum;
    }

    //计算商品总件数
    public Integer getCount(){
        Integer sum = 0;
        if(items!=null){
            for (OrderItemVo item : items) {
                sum += item.getCount();
            }
        }
        return sum;
    }

}
